package com.zany.net.codec;


import org.apache.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import org.apache.mina.filter.codec.demux.MessageEncoder;


public class MyMessageEncoder implements MessageEncoder<String> {
	private Logger logger = Logger.getLogger(MyMessageEncoder.class);

	public void encode(IoSession session, String msg, ProtocolEncoderOutput out)
	    throws Exception { 
		if(logger.isInfoEnabled()){logger.info("MyMessageEncoder.encode()");}
		IoBuffer buf = IoBuffer.allocate(msg.getBytes().length);
		buf.put(msg.getBytes()); 
		buf.flip(); 
		out.write(buf); 
	}
}
